﻿using DataWorks_Sqlite.MappingClass;
using DataWorks_Tools.BasicMethods;
using DataWorks_Tools.MappModals;
using DataWorks_Tools.MappModals.UnifyModals;
using DataWorks_Tools.SpikeDetails;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataWorks_Tools.UnifyDetails
{
    public class UnifyDetailsMethods
    {
        public static async Task<UnifyForOthersModals> GetUnifyModals(dw_props_admin dw_Props_Admin, UnifyModelforContrl modal)
        {
            UnifyForOthersModals unifyForOthersModals = new UnifyForOthersModals();
            await Task.Run(() => {
                var cleannumreg = dw_Props_Admin.clean_numreg.ReComma().Split(',');
                var cleanstringreg = dw_Props_Admin.clean_stringreg.ReComma().Split(',');
                var threadnumber = dw_Props_Admin.cleanthreadnumber;
                var ismultithreads = dw_Props_Admin.ismultithreads;
                var spike_meanpoints = dw_Props_Admin.spike_meanpoints;
                var spike_vairancepoints = dw_Props_Admin.spike_vairancepoints;
                var spike_threadspercentage = dw_Props_Admin.spike_threadspercentage;
                var spike_ratio = dw_Props_Admin.spike_ratio;
                var predictthreads = dw_Props_Admin.predictthreadnumber;

                var selecteddate = modal.selecteddate.ReComma().Split(',');
                var odpath = modal.odpath.YXHPathReplace();
                var cleanedpath = modal.cleanedpath.YXHPathReplace();

                var txtcombpath1st = modal.txtcombpath1st.YXHPathReplace();

                var spikedpath = modal.spikedpath.YXHPathReplace();
                var spikeidx = modal.spikechanidx.ReComma().Split(',');

                var matfilepath = modal.matfilepath.YXHPathReplace();
                var causalorder = modal.causalorder;
                var uncausalorder = modal.uncausalorder;
                var usefilter = modal.usefilter;
                var lowpass = modal.lowpass;
                var matfilestring = modal.matfilename.ReComma().Split(',');
                var predictpath = modal.predictpath.YXHPathReplace();

                var txtcombpath2ed = modal.txtcombpath2ed.YXHPathReplace();

                var cleanrow = new CleanModal();
                cleanrow.odpath = odpath;
                cleanrow.rdpath = cleanedpath;
                cleanrow.datedir = selecteddate;
                cleanrow.errornumber = cleannumreg;
                cleanrow.errornan = cleanstringreg;
                cleanrow.linearConvertModals = modal.linearConvertModals;
                cleanrow.threadnumber = threadnumber;
                unifyForOthersModals.cleanmodal = cleanrow;

                var txt1strow = new MergeModal();
                txt1strow.odpath = cleanedpath;
                txt1strow.rdpath = txtcombpath1st;
                txt1strow.datedir = selecteddate;
                txt1strow.mergetype = mergetype.txt;
                txt1strow.threads = threadnumber;
                unifyForOthersModals.txtmergemodal1st = txt1strow;

                var spikerow = new SpikeModal();
                spikerow.pointcounts = dw_Props_Admin.continuouscount;
                spikerow.odpath = cleanedpath;
                spikerow.rdpath = spikedpath;
                spikerow.datedir = selecteddate;
                spikerow.ratio = spike_ratio;
                spikerow.meanpoints = spike_meanpoints;
                spikerow.vairancepoints = spike_vairancepoints;
                spikerow.threadspercentage = spike_threadspercentage;
                spikerow.spikeidx = SpikeDetailsMethods.YXHGetSpikeIdx(spikeidx);
                spikerow.referdir = txtcombpath1st;
                unifyForOthersModals.spikemodal= spikerow;

                DataPredictModal dataPredictModal = new DataPredictModal();
                dataPredictModal.odpath = cleanedpath;
                dataPredictModal.rdpath = predictpath;
                dataPredictModal.matfilepath = matfilepath;
                dataPredictModal.datedir = selecteddate;
                dataPredictModal.causalorder = causalorder;
                dataPredictModal.uncausalorder = uncausalorder;
                dataPredictModal.matfilename = matfilestring;
                dataPredictModal.lowpass = lowpass;
                dataPredictModal.usefilter = usefilter;
                dataPredictModal.threads = predictthreads;
                unifyForOthersModals.predictmodal= dataPredictModal;


                var txt2edrow = new MergeModal();
                txt2edrow.odpath = predictpath;
                txt2edrow.rdpath = txtcombpath2ed;
                txt2edrow.datedir = selecteddate;
                txt2edrow.mergetype = mergetype.txt;
                txt2edrow.threads = threadnumber;
                unifyForOthersModals.txtmergemodal2ed = txt2edrow;
                unifyForOthersModals.ismultithreads = ismultithreads;
            });
            return unifyForOthersModals;
        }
    }
}
